package com.jdk18.jdk8new;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by xuyiwei on 2018/7/9.
 */
public class AppleSort {

    public static void main(String[] args) {
        List<Apple> apples = new ArrayList<>();
        apples.add(new Apple(6l, 6l));

        apples.add(new Apple(1l, 1l));
        apples.add(new Apple(2l, 2l));
        apples.add(new Apple(4l, 4l));

        apples.add(new Apple(3l, 3l));
        apples.add(new Apple(8l, 8l));

        apples.add(new Apple(5l, 5l));
        apples.add(new Apple(7l, 7l));
        apples.sort(new Comparator<Apple>() {
            @Override
            public int compare(Apple o1, Apple o2) {
                return o1.getWeight().compareTo(o2.getWeight());
            }
        });

        System.out.println(apples);
        List<Apple> greenApples = apples.stream().filter(Apple -> 5l==(long)(Apple.getWeight())).collect(Collectors.toList());
        System.out.println(greenApples);



    }
}
